package com.example.demo.controller;

import com.example.demo.controller.data.ReturnData;
import com.example.demo.sevice.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 上传文件用的接口控制类
 */
@RestController
public class UploadController {

    @Autowired
    UploadService uploadService;
    @PostMapping("uploadAvater")
    public ReturnData uploadAvater(int id, MultipartFile file) throws IOException {
        return uploadService.uploadAvater(id,file);
    }

    /**
     * 通用的上传文件接口
     * @param type  用来区分不同业务的文件，1头像 2朋友圈的图片 3文章图片 4轮播图图片 5个人背景图
     * @param file 上传的文件
     * @return
     * @throws IOException
     */
    @PostMapping("uploadFile")
    public ReturnData uploadFile(int type, MultipartFile file) throws IOException {
        return uploadService.uploadFile(type,file);
    }
}
